<?php
require_once(dirname(__FILE__).'/../../upgrade.php');
class rename_column_categories_catdesc_description extends UPGRADE
{
	/**
	* IsAlreadyUpgraded
	* Do we need to run this classes upgrade script or not ?
	*
	* @return bool true if the upgrade has already run, otherwise false
	*/
	function IsAlreadyUpgraded()
	{
		return $this->ColumnExists($GLOBALS['tablePrefix'].'categories', 'description');
	}

	/**
	* Upgrade
	* Do the actual upgrade of this component. If this is successful all
	* subsequent calls to IsAlreadyUpgraded should return true
	*
	* @return void
	*/
	function Upgrade()
	{
		// If we are upgrading from 1.5 then the description may be null so
		// renaming the table to be not null can cause an error. Update the null
		// descriptions to the empty string to get past this issue.
		$query = 'UPDATE `'.$GLOBALS['tablePrefix'].'categories` SET catDesc="" WHERE catDesc IS NULL';
		$GLOBALS['AKB_DB']->Query($query);

		$query = '
			ALTER TABLE `'.$GLOBALS['tablePrefix'].'categories` CHANGE catDesc description varchar(255) NOT NULL
		';
		$result = $GLOBALS['AKB_DB']->Query($query);
	}

}
?>
